
#pragma once

#include <windows.h>
#include <stdint.h>
#include "IRenderWindow.h"

namespace FlameEngine
{
	class CreateWndCmd;

	class Win32RenderWindow:public IRenderWindow
	{
	public:
		Win32RenderWindow(HINSTANCE hInstance);
		virtual ~Win32RenderWindow();

		virtual void CreateAndRun(CreateWndCmd* pWndCmd);

		virtual void Close();

		static Win32RenderWindow* GetInstance() {return g_pInstance;}

		static LRESULT CALLBACK StaticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

		LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

		void SetWindowPosition(const Int2& position);
		const Int2& GetWindowPosition()const {return m_wndPosition;}

		void SetClientSize(const Int2& size);
		const Int2& GetClientSize() const { return m_wndClientSize; }

		void SetMinClientSize(const Int2& size);
		const Int2& GetMinClientSize() const { return m_minClientWndSize; }

		const Int2& GetWindowSize() const { return m_wndSize; }
		const Int2 GetMonitorResolution() const;

		void SetTitle(const std::string& title);
		const std::string& GetTitle() const {return m_title;}

		void SetWindowState(WindowState ws);
		WindowState GetWindowState() const {return m_wndState;}

		uint32_t GetWndHandle(){return (uint32_t)m_wndHandle;}

		bool IsAllowUserResize() const {return m_allowUserResize;}
		void SetAllowUserResize(bool enable);

		void SetInputActionCallback(InputActionCallback& pCallback);
		void SetSystemMessageCallback(SystemMessageCallback& pCallback);
		void SetOnHostIdleCallback(HostIdleCallback& pCallback);


	protected:
		static Win32RenderWindow* g_pInstance;

		Int2 m_wndSize;
		Int2 m_wndClientSize;
		Int2 m_minClientWndSize;
		Int2 m_wndPosition;
		HWND m_wndHandle;
		HINSTANCE m_hInstance;
		std::string m_title;
		std::string m_appName;

		WindowState m_wndState;
		WindowStyleFlag m_wndStyle;

		bool m_allowUserResize;
		bool m_isDraggingWnd;

		InputActionCallback m_inputCallback;
		SystemMessageCallback m_systemMsgCallback;
		HostIdleCallback m_HostIdelCallback;

		uint32_t GetWin32WndStyle();

		void ReceiveWindowsMsg();

		void ProcessKeyboardInput(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
		void ProcessMouseInput(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
	};
}